Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

рабочая версия калькулятора ресторанного счёта#1

Open
BozhdayA wants to merge 1 commit intomain from
master
Open

рабочая версия калькулятора ресторанного счёта #1
BozhdayA wants to merge 1 commit intomain from
master

Conversation

@BozhdayA
Copy link
Owner

@BozhdayA BozhdayA commented Dec 9, 2022

No description provided.

do
{
System.out.println("На какое количество человек разделить счёт?");
countPeople = scanner.nextInt();
Copy link

@MagicUnderHood MagicUnderHood Dec 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пользователь может ввести на вопрос про количество человек вместо целого числа строку, и приложение упадет. Для стоимости товаров ты обрабатываешь такую ситуацию через hasNextDouble, стоит добавить обработку и для количества людей, чтобы приложение не падало.

int intTotalAmount = (int) totalAmount;
String stringTotalAmount = String.valueOf(intTotalAmount);
int length = stringTotalAmount.length();
char lastDigit = stringTotalAmount.charAt(length-1);
Copy link

@MagicUnderHood MagicUnderHood Dec 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно использовать деление по модулю - %10 для определения последней цифры

case 4:
return "рубля";
default:
return "рублей";
Copy link

@MagicUnderHood MagicUnderHood Dec 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Единственное, не учтена ситуация для чисел 11-19, окончание должно быть "рублей", а сейчас дает рубля для 12-14. Для этого стоит проверять, что округленное totalAmount % 100 между 11 и 19 включительно находится

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@MagicUnderHood MagicUnderHood MagicUnderHood left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /